#include "Stack.h"
#include <iostream>
using namespace std;

Stack::Stack() {
	pTop = NULL;
	size = 0;
}

void Stack::push(int data) {

	Node* pNew = new Node();
	pNew->data = data;
	pNew->next = NULL;

	if (pTop == NULL)
		pTop = pNew;
	else {
		pNew->next = pTop;
		pTop = pNew;
	}

	size++;
}

bool Stack::top(int &data) {
	if (pTop == NULL)
		return false;

	data = pTop->data;
	return true;
}

bool Stack::pop(int &data) {
	if (pTop == NULL)
		return false;

	Node* pDel = pTop;
	pTop = pTop->next;
	data = pDel->data;
	delete pDel;
	size = size - 1;
	return true;
}

void Stack::display() {
	Node* pt = pTop;
	while (pt != NULL) {
		if (pt == pTop)
			cout << "top <- " << pt->data << " <- ";
		else if (pt->next == NULL)
			cout << pt->data << endl;
		else
			cout << pt->data << " <- ";
		pt = pt->next;
	}
}

Stack::~Stack() {

}

/*
 *
 *
 *
 *
 *
 */
